package com.cy.law.app.web;

import com.cy.law.db.entity.Human;
import com.cy.law.utils.SessionUtil;
import com.cy.law.vo.RequestResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AppController {
    @GetMapping(value = "/main")
    public ModelAndView mainHandler() {
        ModelAndView mo = new ModelAndView();
        mo.setViewName("view/main/main");
        return mo;
    }

    @GetMapping("/main/validateSession")
    @ResponseBody
    public RequestResult validateSessionHandler(HttpServletRequest request) {
        Human human = SessionUtil.getHumanSession(request);
        RequestResult result = RequestResult.new0();
        if (human != null) {
            result.setMapData("sessionValid", true);
            result.addMapData("human", human);
        } else {
            result.setMapData("sessionValid", false);
        }
        return result;
    }
}
